package com.zxy.qqmusic.service.impl;

import com.zxy.qqmusic.dao.UserMapper;
import com.zxy.qqmusic.entity.User;
import com.zxy.qqmusic.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 前端用户service实现类
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 增加
     *
     * @param user
     */
    @Override
    public boolean insert(User user) {
        return userMapper.insert(user)>0;
    }

    /**
     * 修改
     *
     * @param user
     */
    @Override
    public boolean update(User user) {
        return userMapper.update(user)>0;
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public boolean delete(Integer id) {
        return userMapper.delete(id)>0;
    }

    /**
     * 根据主键查询整个对象
     *
     * @param id
     */
    @Override
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询所有用户
     */
    @Override
    public List<User> allUser() {
        return userMapper.allUser();
    }

    /**
     * 查看密码是否正确
     *
     * @param username
     * @param password
     */
    @Override
    public boolean verifyPassword(String username, String password) {
        return userMapper.verifyPassword(username,password)>0;
    }

    /**
     * 根据账号查询
     *
     * @param username
     */
    @Override
    public User getByUsername(String username) {
        return userMapper.getByUsername(username);
    }
}
